import 'package:riverpod_t/config/response_model.dart';
import 'package:riverpod_t/net/http_config.dart';
import 'package:riverpod_t/net/net_https.dart';
import 'package:riverpod_t/page/home/data/model/cartoon_model_entity.dart';
import 'package:riverpod_t/page/home/data/repository/home_api.dart';

class HomeRepository {
  /// 请求主数据
  static Future<ResponseModel> getMainData<T>() async {
    ResponseModel? responseModel =
    await NetHttp().request<T>(HomeApi.homeDetailMainURL, method: HttpConfig.mock);
    return responseModel;
  }

  /// 请求系列数据
  static Future<ResponseModel> getSeriesData<T>() async {
    ResponseModel? responseModel =
    await NetHttp().request<T>(HomeApi.homeDetailSeriesURL, method: HttpConfig.mock);
    return responseModel;
  }

  /// 请求推荐数据
  static Future<ResponseModel> getRecommendData<T>() async {
    ResponseModel? responseModel =
    await NetHttp().request<T>(HomeApi.homeDetailRecommendURL, method: HttpConfig.mock);
    return responseModel;
  }

  /// 请求列表数据
  static Future<ResponseModel> getListData<T>(int number) async {
    String getUrl(int number) {
      String urlStr = '';
      if (number == 1) {
        urlStr = HomeApi.homeRecommendList1URL;
      } else if (number == 2) {
        urlStr = HomeApi.homeRecommendList2URL;
      } else if (number == 3) {
        urlStr = HomeApi.homeRecommendList3URL;
      }
      return urlStr;
    }

    ResponseModel responseModel =
    await NetHttp().request<T>(getUrl(number), method: HttpConfig.mock);
    if (number > 3) {
      return ResponseModel(data: CartoonModelData(), code: 0, message: '暂无数据');
    }

    return responseModel;
  }

  /// 请求轮播数据
  static Future<ResponseModel> getBannerData<T>() async {
    ResponseModel? responseModel =
    await NetHttp().request<T>(HomeApi.homeDetailBannersURL, method: HttpConfig.mock);
    return responseModel;
  }
}
